<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Historik</title>
<link rel="stylesheet" type="text/css" href="../CSS/CSS.css" />
<link rel="stylesheet" type="text/css" href="../CSS/header.css" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
if (!window.jQuery) {
    document.write('<script src="../Javascript/jQuery.js"><\/script>');
}
</script>
<script src="../Javascript/Popups.js"></script>
</head>
<body>
<?php 
    include_once("database.php");
    include_once("session_start.php");
    include_once 'admin_check.php';    
    include_once 'header.php';
?>
<div id="page_content">        
	<h1>Historie</h1>
	<?php include_once('get_message.php') ?>	
	<table cellpadding="2">
	    <tr>
	        <th>
	            Materiale
	        </th>
	        <th>
	            Handling
	        </th>
	        <td></td>
	        <th>
	            Bruger
	        </th>
	        <td></td>
	        <th>
	            Dato
	        </th>
	        <td></td>
	        <th>
	            Tid
	        </th>
	    </tr>
	    <?php
	        $query = "SELECT itemhistory.Action, users.UserName, users.UserId, itemhistory.MaterialId, itemhistory.Timestamp FROM itemhistory, users WHERE Users.UserId = itemhistory.UserId;";
	        $stmt = $db -> query($query);
	        while($result= $stmt -> fetch_assoc()){
	            $action = $result["Action"]=="Borrow"? "Lånt":"Afleveret";
	            $exp = explode(' ', $result["Timestamp"]);
	            $day = $exp[0];
	            $clock = $exp[1];
	            echo'<tr>
	                    <td>
	                        <center>';
	                            $query = "SELECT * FROM item WHERE MaterialId =".$result["MaterialId"];
	                            $item = $db -> query($query);
	                            if($item -> num_rows >0 ){
	                                $mat = $item -> fetch_assoc();
	                                echo '<a href="material.php?id='.$result["MaterialId"].'">'.$mat["Name"].'</a>';
	                            }else{
	                                echo '[Deleted]';
	                            }
	                            
	            echo        '</center>                            
	                    </td>
	                    <td>
	                        '.$action.'
	                    </td>
	                    <td>
	                        af
	                    </td>
	                    <td>
	                        <a href="user.php?id='.$result["UserId"].'">'.$result["UserName"].'</a>
	                    </td>
	                    <td>
	                        den 
	                    </td>
	                    <td>';
	                        $day = explode('-', $day);
	                        echo $day[2].'. ';
	                        switch($day[1]){
	                            case 1: 
	                                echo 'Januar';
	                                break;
	                            
	                            case 2:
	                                echo 'Februar';
	                                break;    
	                                
	                            case 3:
	                                echo 'Marts';    
	                                break;
	                                
	                            case 4:
	                                echo 'April';    
	                                break;
	                                
	                            case 5:
	                                echo 'Maj';    
	                                break;
	                                
	                            case 6:
	                                echo 'Juni';    
	                                break;
	                                
	                            case 7:
	                                echo 'Juli';    
	                                break;
	                                
	                            case 8:
	                                echo 'August';    
	                                break;
	                                
	                            case 9:
	                                echo 'September';         
	                                break;
	                                
	                            case 10:
	                                echo 'Oktober';
	                                break;
	                                
	                            case 11:
	                                echo 'November';    
	                                break;
	                                
	                            case 12:
	                                echo 'December';                                                                                                                                                                                                                                                                                                                               
	                                break;
	                        }
	                        echo ' '.ltrim($day[0],"0").'
	                    </td>
	                    <td>
	                        klokken
	                    </td>
	                    <td>';
	                    echo $clock;   
	                echo'</td>                
	                </tr>';
	        }
	        
	        
	    ?>
	</table>
</div>
<?php include_once('footer.php') ?>
</body>
</html>